import advListV from "../view/advList.ejs";
import {getAdvList} from "../api/adv";
import AdvTableV from "../components/AdvTable.ejs";
const advTypeEnum = {
	1:"轮播图广告",
	2:"轮播图底部广告",
	3:"热门回收",
	4:"优品精选"
}
const getAdvListAsync = async function(pageNo=1){
	const data = await getAdvList(pageNo,2);
	document.querySelector("#advTable").innerHTML = AdvTableV({
		...data,
		advTypeEnum
	});
	document.querySelector("#pageUl").onclick = function(e){
		const page = e.target.dataset.page;
		if(page){
			getAdvListAsync(page);
		}
	}
}
export default ()=>{
	return async (req, res) => {
		res.render(advListV());
		getAdvListAsync();
	}
}